import Vue from 'vue';
import VueRouter from 'vue-router';
import api from '../network/apis/api';
import Login from '../views/login/Login.vue';

Vue.use(VueRouter);

const routes = [
  //登录
  {
    path: '/login',
    name: 'Login',
    component: () =>
      import('../views/login/Login.vue'),
  },
  //重定向
  {
    path: '/',
    redirect: '/login', //重定位
  },

  //管理员页面
  {
    path: '/admin',
    name: 'Admin',
    beforeEnter: async (to, from, next) => {
      const {
        data
      } = await api.users.isOnelogin();
      if (!data.status && data.type == 401) {
        alert('你还未登录，请先登录');
        next('/login');
      } else {
        next();
      }
    },
    component: () =>
      import('../views/Admin/Admin.vue'),
    children: [
      //管理员管理功能
      //管理员列表
      {
        path: 'adminsList',
        name: 'AdminsList',
        component: () =>
          import('../components/admins/adminsManage/AdminsList.vue'),
      },
      //修改管理员
      {
        path: 'updateAdmin/:_id',
        name: 'UpdateAdmin',
        component: () =>
          import('../components/admins/adminsManage/UpdateAdmin.vue'),
      },
      //新增管理员
      {
        path: 'addAdmin',
        name: 'AddAdmin',
        component: () =>
          import('../components/admins/adminsManage/AddAdmin.vue'),
      },

      //销售员管理功能
      //销售员列表
      {
        path: 'salesmansList',
        name: 'SalesmansList',
        component: () =>
          import('../components/admins/salesmanManage/salesmansList.vue'),
      },
      //新增销售员
      {
        path: 'addSalesman',
        name: 'AddSalesman',
        component: () =>
          import('../components/admins/salesmanManage/AddSalesman.vue'),
      },
      //修改销售员
      {
        path: 'updateSalesman/:_id',
        name: 'UpdateSalesman',
        component: () =>
          import('../components/admins/salesmanManage/updateSalesman.vue'),
      },

      //保险分类管理；
      //保险分类列表
      {
        path: 'classifyList',
        name: 'ClassifyList',
        component: () =>
          import('../components/admins/classifyMange/classifyList.vue'),
      },
      //新增保险分类
      {
        path: 'addClassify',
        name: 'AddClassify',
        component: () =>
          import('../components/admins/classifyMange/addClassify.vue'),
      },
      //修改保险分类
      {
        path: 'updateClassify',
        name: 'UpdateClassify',
        component: () =>
          import('../components/admins/classifyMange/updateClasify.vue'),
      },

      //保险产品管理
      //保险产品列表
      {
        path: 'productList',
        name: 'ProductList',
        component: () =>
          import('../components/admins/productManage/productList.vue'),
      },
      //新增保险产品
      {
        path: 'addproduct',
        name: 'AddProduct',
        component: () =>
          import('../components/admins/productManage/addProduct.vue'),
      },
      //修改保险产品信息
      {
        path: 'updateProduct/:_id',
        name: 'UpdateProduct',
        component: () =>
          import('../components/admins/productManage/updateProduct.vue'),
      },

      //订单管理
      //查看所有订单
      {
        path: 'orderList',
        name: 'orderList',
        component: () =>
          import('../components/admins/odersManage/ordersList.vue'),
      },
      //订单详情
      {
        path: 'orderDetails/:_id',
        name: 'OrderDetails',
        component: () =>
          import('../components/admins/odersManage/orderDetails.vue'),
      },
      //查看所有退保订单
      {
        path: 'orderRefoundList',
        name: 'orderRefoundList',
        component: () =>
          import('../components/admins/odersManage/orderRefound.vue'),
      },

      //客户管理
      //查看所有客户
      {
        path: 'usersList',
        name: 'UsersList',
        component: () =>
          import('../components/admins/usersManage/usersList.vue'),
      },
      //索赔管理
      //查看所有索赔订单
      {
        path: 'claimsList',
        name: 'ClaimsList',
        component: () =>
          import('../components/admins/claimsManage/claimsManage.vue'),
      },
      //修改订单
      {
        path: 'updateClaims',
        name: 'UpdateClaims',
        component: () =>
          import('../components/admins/claimsManage/updateClaims.vue')
      },
    ],
  },

  //销售员页面
  {
    path: '/salesman',
    name: 'Salesman',
    component: () =>
      import('../views/salesman/salesman.vue'),
    beforeEnter: async (to, from, next) => {
      const {
        data
      } = await api.users.isOnelogin();

      if (!data.status && data.type == 401) {
        alert('你还未登录，请先登录');
        next('/login');
      } else {
        next();
      }
    },
    children: [
      //当前销售员的所有订单
      {
        path: 'getOrdersBySalesman',
        name: 'GetOrdersBySalesman',
        component: () =>
          import('../components/salesmans/myOrdersMange/orderList.vue'),
      },
      //订单详细信息
      {
        path: 'orderMessage',
        name: 'OrderMessage',
        component: () =>
          import('../components/salesmans/myOrdersMange/orderMessage.vue'),
      },
      //修改订单
      {
        path: 'updateOrder/:_id',
        name: 'UpdateOrder',
        component: () =>
          import('../components/salesmans/myOrdersMange/updateOrder.vue'),
      },
      //退保
      {
        path: 'escBaoXian',
        name: 'EscBaoXian',
        component: () =>
          import('../components/salesmans/myOrdersMange/escBaoXian.vue'),
      },
      //销售人员下的客户
      {
        path: 'myUsersList',
        name: 'MyUsersList',
        component: () =>
          import('../components/salesmans/myUsers/myUsersList.vue'),
      },
      //修改用户信息
      {
        path: 'updateUser/:_id',
        name: 'UpdateUser',
        component: () =>
          import('../components/salesmans/myUsers/updateUser.vue'),
      },
      //新增用户
      {
        path: 'addUser',
        name: 'AddUser',
        component: () =>
          import('../components/salesmans/myUsers/addUser.vue'),
      },
      //查看所有理赔信息
      {
        path: 'getAllClaims',
        name: 'GetAllClaims',
        component: () =>
          import('../components/salesmans/claim/getAllClaims'),
      },
      //修改理赔
      {
        path: 'updateClaim/:_id',
        name: 'UpdateClaim',
        component: () =>
          import('../components/salesmans/claim/updateClaim'),
      },
      //新增理赔
      {
        path: 'addOneClaim',
        name: 'AddOneClaim',
        component: () =>
          import('../components/salesmans/claim/addOneClaim'),
      },
      //我的邀请
      {
        path: 'myinvite',
        name: 'Myinvite',
        component: () =>
          import('../components/salesmans/invite/myinvite'),
      },
      //修改我的个人信息
      {
        path: 'updateMyInfo',
        name: 'UpdateMyInfo',
        component: () =>
          import('../components/salesmans/personal/updateMyInfo.vue'),
      },
    ],
  },
];




const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes,
});

export default router;